import { del, type R } from "@/api";
import { http } from "@/utils/http";

const path = "/api/v1/system/role";
const customPath = "/api/v1/role";

enum Index {
  menuCustom = "/menu",
  allCustom = "/all",
  pageCustom = "/page",
  createCustom = "/create",
  editCustom = "/edit",
  editStatusCustom = "/edit/state"
}

export type PageResult = {
  total: number;
  current: number;
  size: number;
  records: Array<Record>;
};

export type Record = {
  id: string;
  name: string;
  code: string;
  status: number;
  remark: string;
  createTime: string;
  updateTime: string;
};

export type MenuCustomRecord = {
  id: string;
  parentId: string;
  menuType: number;
  title: string;
};

export type RoleRecord = {
  id: string;
  name: string;
  code: string;
};

export type ListMenuCustomRecord = Array<MenuCustomRecord>;

export type ListRoleCustomRecord = Array<RoleRecord>;

export type ListMenuIdCustomRecord = Array<string>;

export const apiDel = (id?: string) => {
  return del(path, id);
};

export const pageCustom = (data?: object) =>
  http.post<R<PageResult>, {}>(`${customPath}${Index.pageCustom}`, {
    data: data
  });

export const createCustom = (data?: object) =>
  http.post<R, {}>(`${customPath}${Index.createCustom}`, { data: data });

export const editCustom = (data?: object) =>
  http.post<R, {}>(`${customPath}${Index.editCustom}`, { data: data });

export const editStatusCustom = (data?: object) =>
  http.put(`${customPath}${Index.editStatusCustom}`, { data: data });

export const menuCustom = () =>
  http.get<R<ListMenuCustomRecord>, {}>(`${customPath}${Index.menuCustom}`);

export const menuIdCustom = (id: string) =>
  http.get<R<ListMenuIdCustomRecord>, {}>(
    `${customPath}${Index.menuCustom}/${id}`
  );

export const allCustom = () =>
  http.get<R<ListRoleCustomRecord>, {}>(`${customPath}${Index.allCustom}`);
